/**
 * Logback: the reliable, generic, fast and flexible logging framework.
 * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
 * <p/>
 * This program and the accompanying materials are dual-licensed under
 * either the terms of the Eclipse Public License v1.0 as published by
 * the Eclipse Foundation
 * <p/>
 * or (per the licensee's choosing)
 * <p/>
 * under the terms of the GNU Lesser General Public License version 2.1
 * as published by the Free Software Foundation.
 */
package chapters.configuration;

/**
 * Demonstrates programmatic invocation of Joran.
 */

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.joran.JoranConfigurator;
import ch.qos.logback.core.joran.spi.JoranException;
import ch.qos.logback.core.util.StatusPrinter;

public class MyApp3 {
    final static Logger logger = LoggerFactory.getLogger(MyApp3.class);

    public static void main(String[] args) {
        args = new String[]{"D:\\scm\\oschina\\logback\\logback-examples\\src\\main\\resources\\chapters\\configuration\\duplicate.xml"};
        args = new String[]{"D:\\scm\\oschina\\logback\\logback-examples\\src\\main\\resources\\chapters\\configuration\\restricted.xml"};
        //覆盖默认的累积行为
        args = new String[]{"D:\\scm\\oschina\\logback\\logback-examples\\src\\main\\resources\\chapters\\configuration\\additivityFlag.xml"};
        //设置上下文名称
        args = new String[]{"D:\\scm\\oschina\\logback\\logback-examples\\src\\main\\resources\\chapters\\configuration\\contextName.xml"};
        //变量替换
        args = new String[]{"D:\\scm\\oschina\\logback\\logback-examples\\src\\main\\resources\\chapters\\configuration\\variableSubstitution1.xml"};
        //变量替换，当需要很多变量时，更方便的做法是在一个单独的文件里声明所有变量
        args = new String[]{"D:\\scm\\oschina\\logback\\logback-examples\\src\\main\\resources\\chapters\\configuration\\variableSubstitution3.xml"};
        //变量替换，嵌套变量替换
        args = new String[]{"D:\\scm\\oschina\\logback\\logback-examples\\src\\main\\resources\\chapters\\configuration\\variableSubstitution3.xml"};
        //jndi中获取变量
        args = new String[]{"D:\\scm\\oschina\\logback\\logback-examples\\src\\main\\resources\\chapters\\configuration\\insertFromJNDI.xml"};
        //文件包含(文件路径有问题)
        args = new String[]{"D:\\scm\\oschina\\logback\\logback-examples\\src\\main\\resources\\chapters\\configuration\\containingConfig.xml"};
        //ConsoleAppender测试
        args = new String[]{"D:\\scm\\oschina\\logback\\logback-examples\\src\\main\\resources\\chapters\\appenders\\conf\\logback-Console.xml"};
        //TimeBasedRollingPolicy 或许是最受流行的滚动策略
        args = new String[]{"D:\\scm\\oschina\\logback\\logback-examples\\src\\main\\resources\\chapters\\appenders\\conf\\logback-RollingTimeBased.xml"};
        //基于大小和时间的归档
        args = new String[]{"D:\\scm\\oschina\\logback\\logback-examples\\src\\main\\resources\\chapters\\appenders\\conf\\logback-sizeAndTime.xml"};

        // assume SLF4J is bound to logback in the current environment
        LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();

        try {
            JoranConfigurator configurator = new JoranConfigurator();
            configurator.setContext(context);
            // Call context.reset() to clear any previous configuration, e.g. default
            // configuration. For multi-step configuration, omit calling context.reset().
            context.reset();
            configurator.doConfigure(args[0]);
        } catch (JoranException je) {
            // StatusPrinter will handle this
        }
        StatusPrinter.printInCaseOfErrorsOrWarnings(context);


        for (int i = 0; i < 100000; i++) {
            logger.info("Entering application." + i);
            Foo foo = new Foo();
            foo.doIt();
            logger.info("Exiting application." + i);
        }

    }
}
